package com.yuba.front.controller.like;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.yuba.common.core.domain.R;
import com.yuba.common.log.annotation.Log;
import com.yuba.common.log.enums.BusinessType;
import com.yuba.common.mybatis.core.page.PageQuery;
import com.yuba.common.mybatis.core.page.TableDataInfo;
import com.yuba.common.web.core.BaseController;
import com.yuba.front.domain.bo.LikePostsBo;
import com.yuba.front.domain.vo.LikePostsVo;
import com.yuba.front.service.ILikePostsService;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 帖子点赞管理接口
 *
 * @author modakai
 * @date 2024-12-02
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/like/posts")
public class LikePostsController extends BaseController {

    private final ILikePostsService likePostsService;

    /**
     * 查询文章点赞列表
     */
    @SaCheckPermission("like:posts:list")
    @GetMapping("/list")
    public TableDataInfo<LikePostsVo> list(LikePostsBo bo, PageQuery pageQuery) {
        return likePostsService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出文章点赞列表
     */
//    @SaCheckPermission("like:posts:export")
//    @Log(title = "文章点赞", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(LikePostsBo bo, HttpServletResponse response) {
//        List<LikePostsVo> list = likePostsService.queryList(bo);
//        ExcelUtil.exportExcel(list, "文章点赞", LikePostsVo.class, response);
//    }

    /**
     * 获取文章点赞详细信息
     *
     * @param likeId 主键
     */
    @SaCheckPermission("like:posts:query")
    @GetMapping("/{likeId}")
    public R<LikePostsVo> getInfo(@NotNull(message = "主键不能为空")
                                  @PathVariable Long likeId) {
        return R.ok(likePostsService.queryById(likeId));
    }


    /**
     * 修改文章点赞
     */
//    @SaCheckPermission("like:posts:edit")
//    @Log(title = "文章点赞", businessType = BusinessType.UPDATE)
//    @RepeatSubmit()
//    @PutMapping()
//    public R<Void> edit(@Validated(EditGroup.class) @RequestBody LikePostsBo bo) {
//        return toAjax(likePostsService.updateByBo(bo));
//    }

    /**
     * 删除文章点赞
     *
     * @param likeIds 主键串
     */
    @SaCheckPermission("like:posts:remove")
    @Log(title = "文章点赞", businessType = BusinessType.DELETE)
    @DeleteMapping("/{likeIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] likeIds) {
        return toAjax(likePostsService.deleteWithValidByIds(List.of(likeIds), true));
    }

}
